import {
  selectCourseTeachList
} from '@/api/teach.js'
import CourseChapter from '@/components/Course/CourseChapter/index.vue'
export default {
  components: {
    CourseChapter
  },
  data() {
    return {
      classDatas: [],
      classValue: null,
      headercellstyle: 'background:#c90a5b;color:#fff;text-align:center;font-size:9px;font-weight:500;',
      param: {
        courseId: this.$route.query.courseId
      },
      tableDatas: []
    }
  },
  created() {
    this.getDatas()
  },
  watch: {
    classValue: function() { // 监听班级选择变化
      this.selectCourseTeachList()
    },
    $route: {
      handler() {
        this.selectCourseTeachList()
      },
      deep: true
    }
  },
  methods: {
    getRowClass({ row, column, rowIndex, columnIndex }) {
      // console.log(rowIndex)
      if (rowIndex === 0) {
        return 'background: #1dabec; color:#fff; text-align:center; font-weight:500;'
      } else {
        return ''
      }
    },
    getDatas() {
      this.selectCourseTeachList()
    },
    selectCourseTeachList() {
      selectCourseTeachList(this.param).then(response => {
        if (response.code === 20000 || response.code === 200) {
        // console.log(response.data)
          this.tableDatas = response.data
        // console.log(this.tableDatas)
        } else {
          this.$message({
            type: 'info',
            message: '学生获取失败'
          })
        }
      })
    },
    time_difference(start_date, end_date) { // 计算属性的 getter
      if (!start_date) {
        return '没有开始时间'
      } else if (!end_date) {
        return '没有结束时间'
      } else {
        let time_str = ''
        const data1 = new Date(start_date) // 得到毫秒时间戳
        const data2 = new Date(end_date) // 得到毫秒时间戳
        var difference_time = (data2 - data1)
        if(difference_time<0){
          return '时间开始小于结束'
        }
        const time_hour = Math.floor(difference_time/1000/60/60) // 换算成小时
        time_str += time_hour + '时'
        difference_time -= time_hour*60*60*1000
        const time_minute = Math.floor(difference_time/1000/60)
        time_str += time_minute + '分' // 换算成分
        difference_time -= time_minute*60*1000
        const time_second = Math.floor(difference_time/1000) // 换算成秒
        time_str += time_second + '秒'
        return time_str
      }
    }
  }
}
